﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WGCSFramework.validations.numbers
{
    public class WgNumbers
    {
        public int validateNumberInString(string text)
        {
            return this.validateNumberInString(text, 0, 999999, 0);
        }

        public int validateNumberInString(string text, int min, int max)
        {
            return this.validateNumberInString(text, min, max, 0);
        }

        public int validateNumberInString(string text, int min, int max, int defaultValue)
        {
            int n = defaultValue;
            if (text == "") return n;
            try
            {
                n = Int16.Parse(text);
            }
            catch
            {
                n = defaultValue;
            }
            if (n < min) n = min;
            else if (n > max) n = max;
            return n;
        }
    }
}
